#from tkinter import Y
import matplotlib.pyplot as plt
import numpy as np
file_name1 = "Ea1.txt"#sp3
file_name2 = "Ea2.txt"#sp2
file_name3 = "Ea3.txt"#x值
a = []
b = []
c = []
file1 = open(file_name1, mode = 'r')
for line in file1:
    line = line.split()
    a.append(line)
file1.close()

file2 = open(file_name2, mode = 'r')
for line in file2:
    line = line.split()
    b.append(line)
file2.close()

file3 = open(file_name3, mode = 'r')
for line in file3:
    line = line.split()
    c.append(line)
file2.close()

a1 = []
for m in a:
    a1.append(float(m[0]))
a = a1#将list转化为float
b1 = []
for m in b:
    b1.append(float(m[0]))
b = b1
c1 = []
for m in c:
    c1.append(float(m[0]))
c = c1


x = np.linspace(0,28,10000)
#y = 1/(1+25*x*x)
Y = np.zeros((10000,2))

n = 7
# for i in range(0,2):
#     if i == 0:
#             p = 0
#             q = n[0]
#     else:
#         p = q
#         q = q + n[i]
p = 0
q = 7
for k in range(0, 10000):
    for j in range(p, q):
        if j == p:
            Y[k][0] = a[q-1]
        else:
            Y[k][0] = Y[k][0]*(x[k]-c[q - (j-p+1)]) + a[q - (j-p+1)]
for k in range(0, 10000):
    for j in range(p, q):
        if j == p:
            Y[k][1] = b[q-1]
        else:
            Y[k][1] = Y[k][1]*(x[k]-c[q - (j-p+1)]) + b[q - (j-p+1)]
        #print(Y[k][i])
Y1 = np.array(Y)

for i in range(0, 2):
    plt.plot(x,Y1[:,i])
plt.legend(['Sp1','Sp2'])

plt.show()
plt.savefig("Ea.png")